#!/bin/bash
# 卸载旧版本
yum remove docker \
        docker-client \
        docker-client-latest \
        docker-common \
        docker-latest \
        docker-latest-logrotate \
        docker-logrotate \
        docker-engine

# 安装包
yum install -y yum-utils

# 设置镜像仓库
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# 阿里云镜像
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 安装Docker
yum install docker-ce docker-ce-cli containerd.io

# 配置镜像加速
sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://c9bhpb0b.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload

# 启动Docker
systemctl start docker

# 安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.27.4/docker-compose-"$(uname -s)"-"$(uname -m)" > /usr/local/bin/docker-compose
sudo chmod a+x /usr/local/bin/docker-compose
